package dto;

import java.io.File; 
import java.util.ArrayList;
import java.util.List; 
import javax.swing.filechooser.FileSystemView; 

import util.general.*;
/**
 * 
 * @author ThaiBaoDoan
 *  Partition 
 */
public class TotalPartition extends TotalFileBase{
	
	private String _stdPartionLabel; //Win7 , Data
	private String _stdPartionIndex; // C, D, E ...
	private long  _lPartitionSize;
	private long  _lPartitionFreeSize;
	public static List<TotalPartition> GetAllPartion()
	{
		 File[] roots = File.listRoots(); 
		 FileSystemView fsv = FileSystemView.getFileSystemView();
		 List<TotalPartition> totalPart = new ArrayList<TotalPartition>(roots.length);
		 
		 for(int i = 0 ; i < roots.length ; i++)
		 {
			 TotalPartition total = new TotalPartition();
			 total.set_file(roots[i]); 
			 total.set_lPartitionSize(roots[i].getTotalSpace());
			 total.set_lPartitionFreeSize(roots[i].getFreeSpace());
			 String temp_fullname = fsv.getSystemDisplayName(roots[i]);
			  if(temp_fullname.length() >0)
			 total.set_stdFullName(temp_fullname.substring(0,temp_fullname.lastIndexOf("("))); 
			 total.set_fileType(config_general.GetPartitionType(roots[i].toString()));
			 totalPart.add(total);
			 
		 }
		 
		 return totalPart;
		
	}
	public static TotalPartition GetPartition(String Part)
	{
		 File file = new File(Part);
		 FileSystemView fsv = FileSystemView.getFileSystemView();
		 TotalPartition totalPart = new TotalPartition();
		 totalPart.set_file(file); 
		 totalPart.set_lPartitionSize(file.getTotalSpace());
		 totalPart.set_lPartitionFreeSize(file.getFreeSpace());
		 String temp_fullname = fsv.getSystemDisplayName(file);
		 System.out.println("full name: "+ temp_fullname);
		  if(temp_fullname.length() >0 && temp_fullname.contains("(") )
			  totalPart.set_stdFullName(temp_fullname.substring(0,temp_fullname.lastIndexOf("("))); 
		  totalPart.set_fileType(config_general.GetPartitionType(file.toString()));
		 return totalPart;
	}
	public static String[] GetAllPartitionIndex()
	{
		 File[] roots = File.listRoots();  
		 String [] result = new String [roots.length];
		 
		 for(int i = 0 ; i < roots.length ; i++)
		 {
			 TotalPartition total = new TotalPartition();
			 total.set_file(roots[i]); 
			 result[i] =  total.get_stdPartionIndex();
		 }
		 
		 return result;
		
	}

	public String get_stdFullName() {
		return _stdPartionLabel;
	}

	public void set_stdFullName(String _stdFullName) {
		this._stdPartionLabel = _stdFullName;
	}

	public String get_stdPartionIndex() {
		return this._file.toString().substring(0,1);
	}

	public void set_stdPartionIndex(String _stdPartionIndex) {
		this._stdPartionIndex = _stdPartionIndex;
	}
	public long get_lPartitionSize() {
		return _lPartitionSize;
	}
	public void set_lPartitionSize(long _lPartitionSize) {
		this._lPartitionSize = _lPartitionSize;
	}
	public long get_lPartitionFreeSize() {
		return _lPartitionFreeSize;
	}
	public void set_lPartitionFreeSize(long _lPartitionFreeSize) {
		this._lPartitionFreeSize = _lPartitionFreeSize;
	}

	
	

}
